

class Service {
    public static void print(Object obj) {
	try {
	    synchronized (obj) {
		while (true) {
		    System.out.println(Thread.currentThread().getName());
		    Thread.sleep(1000);
		}
	    }

	} catch (Exception e) {
	    // TODO: handle exception
	    e.printStackTrace();
	}
    }
}

class ThreadA extends Thread {
    private Service service;

    public ThreadA(Service service) {
	super();
	this.service = service;

    }

    public void run() {
	service.print(new Object());
    }
}

class ThreadB extends Thread {
    private Service service;

    public ThreadB(Service service) {
	super();
	this.service = service;

    }

    public void run() {
	service.print(new Object());
    }
}

public class String常量池引发问题 {
    public static void main(String args[]) {

	Service service = new Service();
	ThreadA a = new ThreadA(service);
	a.setName("A");
	ThreadB b = new ThreadB(service);
	b.setName("B");
	a.start();
	b.start();

    }
}
